﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Linq.Expressions;
using Newtonsoft.Json.Linq;
using WebGrease.Css.Extensions;

using CanDoo;
using CanDoo.Core;
using CanDoo.Data;
using CanDoo.Web;
using CanDoo.FineUI;
using CanDoo.Extensions;
using CanDoo.Oil.Core.Models;
using CanDoo.Oil.Core.Contracts;
using CanDoo.Admin.Core.Contracts;
using CanDoo.Core.Data;
using FineUIPro;

namespace CanDoo.Oil.WebApp.proWarehouse
{
    public partial class Default : ListPageBase<IWarehouseContract, Warehouse>
    {


        public IWarehouseTypeContract WarehouseTypeContract { get; set; }

        #region 方法
        protected override void InitGrid()
        {
            Selector = p => new
            {
                p.Code,
                p.WarehouseType,
                p.WarehouseTypeId,
                p.Manager,
                p.Tel,
                p.Address,
                p.Remark,
                p.Id,
                p.Name
            };
            base.InitGrid();
        }

        protected override void Search()
        {
            var key = SearchKey.GetValue();
            var warehousetypeId = SearchWarehouseType.GetValue().ToLong();
            if(string.IsNullOrEmpty(key) == false)
            {
                Filter = Filter.And(p => 
                    p.Name.Contains(key) 
                    || p.Tel.Contains(key)
                    || p.Code.Contains(key)
                    || p.Address.Contains(key)
                );
            }
            if (warehousetypeId >  0L)
                Filter = Filter.And(p => p.WarehouseTypeId == warehousetypeId);

            var isDeleted = ManageRecycle.Checked;
            Filter = Filter.And(p => p.IsDeleted == isDeleted);
        }
        #endregion

        #region 事件
        #region Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //FineUIListHelper.BindDDL<WarehouseType>("仓库类别",WarehouseTypeContract.GetResolvedTree(), 0L, SearchWarehouseType);
                FineUIListHelper.BindDDL(WarehouseTypeContract.EntityName, this.WarehouseTypeContract.GetSelectList(), 0L, SearchWarehouseType);
                InitGrid();
            }
        }
        #endregion

        #endregion 事件

    }
}
